package com.zzyl.controller;


import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@Api(tags = "护理项目相关接口")
@RequestMapping("/nursing_project")
@RequiredArgsConstructor
public class NursingProjectController extends BaseController{

    private final NursingProjectService nursingProjectService;

    /**
     * 护理项目分页查询
     * @param name 项目名字
     * @param status 项目状态
     * @param pageNum 页码
     * @param pageSize 页面大小
     */
    @GetMapping
    public ResponseResult<PageResponse<NursingProjectVO>> getPage(
            @ApiParam(value = "项目名称") @RequestParam(value = "name", required = false) String name,
            @ApiParam(value = "项目状态") @RequestParam(value = "status", required = false) Integer status,
            @ApiParam(value = "当前页码", defaultValue = "1") @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页大小", defaultValue = "10") @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize
    ) {
        return ResponseResult.success(nursingProjectService.getPage(name, status, pageNum, pageSize));
    }

    // ... (其他依赖和成员变量)

    /**
     * 添加护理项目。
     *
     * @param nursingProjectDto 护理项目数据传输对象，包含添加护理项目的详细信息。
     * @return 返回添加操作的结果，包括成功与否、错误信息等。
     */
    @ApiOperation(value = "添加护理项目", notes = "根据传入的NursingProjectDto添加新的护理项目")
    @PostMapping
    public ResponseResult<String> addNursingProject(
            @ApiParam(name = "nursingProjectDto", value = "护理项目详细信息", required = true)
            @RequestBody NursingProjectDto nursingProjectDto) {
        return toAjax(nursingProjectService.addNursingProject(nursingProjectDto));
    }

    /**
     * 根据id查询护理项目。
     *
     * @param id 护理项目id
     * @return 返回查询结果，包括护理项目详细信息。
     */
    @ApiOperation(value = "根据ID获取护理项目", notes = "通过ID获取单个护理项目的详细信息")
    @GetMapping("/{id}")
    public ResponseResult<NursingProjectVO> getNursingProjectById(
            @ApiParam(name = "id", value = "护理项目ID", required = true)
            @PathVariable Long id) {
        return success(nursingProjectService.getNursingProjectById(id));
    }

    /**
     * 更新护理项目。
     *
     * @param nursingProjectDto 护理项目数据传输对象，包含更新护理项目的详细信息。
     * @return 返回更新操作的结果，包括成功与否、错误信息等。
     */
    @ApiOperation(value = "更新护理项目", notes = "根据传入的NursingProjectDto更新已存在的护理项目")
    @PutMapping
    public ResponseResult<String> updateNursingProject(
            @ApiParam(name = "nursingProjectDto", value = "护理项目详细信息", required = true)
            @RequestBody NursingProjectDto nursingProjectDto) {
        return toAjax(nursingProjectService.updateNursingProject(nursingProjectDto));
    }

    /**
     * 删除护理项目。
     *
     * @param id 护理项目id
     * @return 返回删除操作的结果，包括成功与否、错误信息等。
     */
    @ApiOperation(value = "删除护理项目", notes = "根据ID删除护理项目")
    @DeleteMapping("/{id}")
    public ResponseResult<String> deleteNursingProject(
            @ApiParam(name = "id", value = "护理项目ID", required = true)
            @PathVariable Long id) {
        return toAjax(nursingProjectService.deleteNursingProject(id));
    }

    /**
     * 更新护理项目的状态。
     *
     * @param id 护理项目id
     * @param status 护理项目状态
     * @return 返回更新操作的结果，包括成功与否、错误信息等。
     */
    @PutMapping("{id}/status/{status}")
    public ResponseResult<String> updateNursingProjectStatus(
            @ApiParam(name = "id", value = "护理项目ID", required = true)
            @PathVariable Long id,
            @ApiParam(name = "status", value = "护理项目状态", required = true)
            @PathVariable Integer status
    ) {
        return toAjax(nursingProjectService.updateStatus(id,status));
    }

    /**
     * 获取所有护理项目。
     *
     * @return 返回所有护理项目的列表。
     */
    @GetMapping("all")
    public ResponseResult<List<NursingProjectVO>> getNursingProjectList() {
        return success(nursingProjectService.getNursingProjectList());
    }
}
